package com.jfok.server.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jfok.server.service.SystemAndLoginInfoService;
import com.jfok.shared.SystemAndLoginInfo;

@Controller
public class SystemAndLoginInfoController {

	@Resource
	private SystemAndLoginInfoService systemAndLoginInfoService;

	@RequestMapping("/systemandlogininfo.do")
	public synchronized @ResponseBody
	SystemAndLoginInfo getSystemAndLoginInfo(HttpServletRequest request) {
		return systemAndLoginInfoService.getSystemAndLoginInfo(request);
	}

	@RequestMapping("/restarttomcat.do")
	public synchronized @ResponseBody
	void restartTomcat(HttpServletRequest request) {
		System.out.println("--------restarttomcat---------");
		Runtime run = Runtime.getRuntime();
		try {
			String s = SystemAndLoginInfoController.class.getResource("").getPath().replace("%20", " ");
			s = s.substring(0, s.indexOf("WEB-INF") + 8) + "restarttomcat.exe";
			@SuppressWarnings("unused")
			Process pro = run.exec(s);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	@RequestMapping("/updateserverdate.do")
	public @ResponseBody
	String restartServerDate(String d, String t) {

		System.out.println(d);
		System.out.println(t);
		String result = "";
		try {
			java.lang.Runtime.getRuntime().exec("cmd /c date " + d);
		} catch (java.io.IOException e) {
			e.printStackTrace();
			result += e.getCause();
		}

		try {
			java.lang.Runtime.getRuntime().exec("cmd /c time " + t);
		} catch (java.io.IOException e) {
			e.printStackTrace();
			result += "<br/>" + e.getCause();
		}
		return result;
	}

}
